Skip to content

feat: django-axes prefers forwarded ip address#481

Merged
charn merged 2 commits into
mainfrom
PT-2026/django-axes-config
Mar 24, 2026
Merged

feat: django-axes prefers forwarded ip address#481
charn merged 2 commits into
mainfrom
PT-2026/django-axes-config

Conversation

@charn

@charn charn commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Prioritize HTTP_X_FORWARDED_FOR for django-axes similar to audit logs with the get_client_ip.

https://django-axes.readthedocs.io/en/latest/4_configuration.html#configuring-reverse-proxies

Refs: PT-2026

@charn charn requested a review from a team as a code owner March 24, 2026 13:47
Comment thread palvelutarjotin/settings.py
@azure-pipelines

Copy link
Copy Markdown

KULTUS-API branch is deployed to platta: https://kultus-pr481.api.dev.hel.ninja 🚀🚀🚀

@charn charn force-pushed the PT-2026/django-axes-config branch from c45355c to 730b7e4 Compare March 24, 2026 14:03
Refs: PT-2026
@charn charn force-pushed the PT-2026/django-axes-config branch from 730b7e4 to cda2b96 Compare March 24, 2026 14:07
Prioritize `HTTP_X_FORWARDED_FOR` for django-axes similar
to audit logs with the get_client_ip.

Refs: PT-2026
@charn charn force-pushed the PT-2026/django-axes-config branch from cda2b96 to c62e9b0 Compare March 24, 2026 14:12
AXES_FAILURE_LIMIT = 5
AXES_COOLOFF_TIME = 1 # hour after locked out, user will be able to attempt login
AXES_IPWARE_META_PRECEDENCE_ORDER = ["HTTP_X_FORWARDED_FOR", "REMOTE_ADDR"]
AXES_IPWARE_PROXY_COUNT = 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The AXES_IPWARE_PROXY_COUNT is hardcoded to 1, creating an IP spoofing vulnerability in local development and causing incorrect IP detection in multi-proxy environments.
Severity: HIGH

Suggested Fix

Make the AXES_IPWARE_PROXY_COUNT setting configurable via an environment variable, similar to other infrastructure-dependent settings like USE_X_FORWARDED_HOST. This allows each deployment environment (local, staging, production) to specify the correct number of proxies.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: palvelutarjotin/settings.py#L451

Potential issue: The setting `AXES_IPWARE_PROXY_COUNT` is hardcoded to `1`. This assumes
a fixed infrastructure with exactly one reverse proxy, which is not guaranteed across
all deployment environments. In local development environments without a proxy, this
configuration makes the `django-axes` rate-limiting feature vulnerable to IP spoofing,
as it will incorrectly trust a client-supplied `X-Forwarded-For` header. Conversely, in
production environments with more than one proxy, it will identify an intermediate
proxy's IP instead of the actual client's, undermining the effectiveness of rate
limiting.

@sonarqubecloud

Copy link
Copy Markdown

@azure-pipelines

Copy link
Copy Markdown

KULTUS-API branch is deployed to platta: https://kultus-pr481.api.dev.hel.ninja 🚀🚀🚀

@charn charn merged commit 0a6bd10 into main Mar 24, 2026
31 checks passed
@charn charn deleted the PT-2026/django-axes-config branch March 24, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants